/**
 * Customization of the ItemizedOverlay.
 * 
 * @author Alican Ozgoren
 * @version 12/14/2012
 */

package edu.brockport.shuttleapp;

import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> 
{

   private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
   private Context context;

   //----------------------------------------------------------
   public CustomItemizedOverlay(Drawable defaultMarker) 
   {
        super(boundCenterBottom(defaultMarker));
   }

   //----------------------------------------------------------
   public CustomItemizedOverlay(Drawable defaultMarker, Context context) 
   {
        this(defaultMarker);
        this.context = context;
   }

   //----------------------------------------------------------
   @Override
   protected OverlayItem createItem(int i) 
   {
      return mapOverlays.get(i);
   }

   //----------------------------------------------------------
   @Override
   public int size() 
   {
      return mapOverlays.size();
   }

   //----------------------------------------------------------
   @Override
   protected boolean onTap(int index) 
   {
	   String title = mapOverlays.get(index).getTitle();
	   TextView pinInfoTextView = (TextView) ((MapActivity) context).findViewById(R.id.showPinInfo);
	   pinInfoTextView.setText(title);
	  
	   return true;
   }

   //----------------------------------------------------------
   public void addOverlay(OverlayItem overlay) 
   {
	   mapOverlays.add(overlay);
	   populate();
   }

}
